package com.qqtech.qquan.ad.service;

import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Service;

import com.qqtech.core.common.enums.YesNoEnum;
import com.qqtech.core.frame.dao.BaseDao;
import com.qqtech.core.frame.model.PageKit;
import com.qqtech.core.frame.model.PageOrder;
import com.qqtech.core.frame.service.BaseServiceImpl;

import com.qqtech.qquan.ad.dao.AdBaseDao;
import com.qqtech.qquan.ad.enums.AdTypeDictEnum;
import com.qqtech.qquan.ad.model.*;

@Service
public class AdBaseServiceImpl extends BaseServiceImpl<AdBase>
		implements AdBaseService {
	public static final Logger log = LoggerFactory.getLogger(AdBaseServiceImpl.class);
	
	@Resource
	private AdBaseDao adBaseDao;

	@Override
	protected BaseDao<AdBase> getBaseDao() {
		return adBaseDao;
	}

	@Override
	public List<AdBaseVo> getAdListByType(AdTypeDictEnum adTypeDictEnum,Integer communityId) {
		AdBaseQuery adBaseQuery=new AdBaseQuery();
		adBaseQuery.setType(adTypeDictEnum.getCode());
		adBaseQuery.setStatus(YesNoEnum.YES.getCode());
		adBaseQuery.setCommunityId(communityId);
		Pageable pageKit1 = new PageKit(1, Integer.MAX_VALUE, new PageOrder(Direction.ASC, "oidx"));
		List<AdBaseVo> list=adBaseDao.queryList(adBaseQuery,pageKit1);
		if(null==list||list.size()<=0){
			adBaseQuery.setCommunityId(null);
			adBaseQuery.setNoCommunityId(YesNoEnum.YES.getCode());
			list=adBaseDao.queryList(adBaseQuery,pageKit1);
		}
		return list;
	}
	
}